home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Text Editor / Source / TextEditorActivation.cpp < prev    next >
Encoding:
Text File  |  1995-12-13  |  21.2 KB  |  787 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2.  
  3.     File:            TextEditorActivation.cpp
  4.     
  5.     Description:    TextEditor's activation protocol methods.                    
  6.     
  7.     Written by:        Steve Smith
  8.     
  9.     Copyright:        © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  10.     
  11. ------------------------------------------------------------------------------*/
  12.  
  13. // Notification that this is a SOM source file
  14. #define SampleCode_TextEditor_Class_Prototypes
  15. // define underscore (_) field names
  16. #define VARIABLE_MACROS
  17.  
  18. #ifndef _COMPILERDEFS_
  19. #include "CompDefs.h"
  20. #endif
  21.  
  22. // -- OpenDoc Utilities --
  23.  
  24. #ifndef _EXCEPT_
  25. // Exceptions define several important macros (e.g. CHECKENV)
  26. // which are used in the SOM method dispatch glue. If Except.h
  27. // is not included early enough, exceptions may not be thrown
  28. // correctly when returning from a SOM method with "ev" parameter set.
  29. #include <Except.h>
  30. #endif
  31.  
  32. // -- TextEditor Includes
  33.  
  34. #ifndef SOM_SampleCode_TextEditor_xih
  35. #include "TextEditor.xih"
  36. #endif
  37.  
  38. #ifndef _TEXTEDITORDEF_
  39. #include "TextEditorDef.h"
  40. #endif
  41.  
  42. #ifndef _TEXTEDITORUTILS_
  43. #include "TextEditorUtils.h"
  44. #endif
  45.  
  46. #ifndef _TEXTEDITORGLOBALS_
  47. #include "TextEditorGlobals.h"
  48. #endif
  49.  
  50. // -- OpenDoc Includes --
  51.  
  52. #ifndef _ODTYPES_
  53. #include <ODTypes.h>
  54. #endif
  55.  
  56. #ifndef SOM_Module_OpenDoc_Commands_defined
  57. #include <CmdDefs.xh>
  58. #endif
  59.  
  60. #ifndef SOM_ODFrame_xh
  61. #include <Frame.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODPart_xh
  65. #include <Part.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODStorageUnit_xh
  69. #include <StorageU.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODSession_xh
  73. #include <ODSessn.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODDispatcher_xh
  77. #include <Disptch.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODArbitrator_xh
  81. #include <Arbitrat.xh>
  82. #endif
  83.  
  84. // -- OpenDoc Utilities --
  85.  
  86. #ifndef _FOCUSLIB_
  87. #include <FocusLib.h>
  88. #endif
  89.  
  90. #ifndef _ODUTILS_
  91. #include <ODUtils.h>
  92. #endif
  93.  
  94. #ifndef _TEMPOBJ_
  95. #include <TempObj.h>
  96. #endif
  97.  
  98. // -- Textension Includes --
  99.  
  100. #ifndef _Textension_
  101. #include "Textension.h"
  102. #endif
  103.  
  104. #ifndef _TSMTextension_
  105. #include "TSMTextension.h"
  106. #endif
  107.  
  108. // -- ScriptRunner Includes --
  109.  
  110. #ifndef SOM_PaletteExt_xh
  111. #include "PaletteExt.xh"
  112. #endif
  113.  
  114.  
  115. //------------------------------------------------------------------------------
  116. // Method:        BeginRelinquishFocus
  117. // Origin:        ODPart
  118. //
  119. // Description:    This method is called when another part (or possibly
  120. //                ourself) is requesting a focus for one of its display
  121. //                frames. Returning true means we are willing to give
  122. //                up the requested focus.
  123. //
  124. //                The part willingly gives up any focus unless it is the
  125. //                modal focus which we don't want to give up until we
  126. //                are completely done displaying a modal dialog.
  127. //------------------------------------------------------------------------------
  128. #pragma segment TextEditorActivation
  129.  
  130. SOM_Scope    ODBoolean
  131. SOMLINK        TextEditor__BeginRelinquishFocus
  132.             (
  133.                 SampleCode_TextEditor*        somSelf,
  134.                 Environment*                ev,
  135.                 ODTypeToken                    focus,
  136.                 ODFrame*                    ownerFrame,
  137.                 ODFrame*                    proposedFrame
  138.             )
  139. {
  140.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  141.     SOMMethodDebug("TextEditor","BeginRelinquishFocus");
  142.  
  143.     ODBoolean willRelinquish = kODTrue;
  144.  
  145.     SOM_TRY
  146.     
  147.         // Another part is trying to put up a Modal dialog while we
  148.         // are currently displaying ours. Deny the request.
  149.         if ( focus == gGlobals->fModalFocus )
  150.         {
  151.             TempODPart proposedPart = proposedFrame->AcquirePart(ev);
  152.             if ( !ODObjectsAreEqual(ev, proposedPart, _fSelf) )
  153.                 willRelinquish = kODFalse;
  154.         }
  155.         else if (focus == gGlobals->fClipboardFocus)
  156.         {
  157.             // If the part has the clipboard focus, then a transaction is in
  158.             // progress and we don't want to be interrupted.
  159.             willRelinquish = kODFalse;
  160.         }
  161.  
  162.     SOM_CATCH_ALL
  163.         willRelinquish = kODTrue;
  164.     SOM_ENDTRY
  165.         
  166.     return willRelinquish;
  167. }
  168.  
  169. //------------------------------------------------------------------------------
  170. // Method:        CommitRelinquishFocus
  171. // Origin:        ODPart
  172. //
  173. // Description:    This method is called when it is actually time to give
  174. //                up a focus that had been requested by another part (or
  175. //                possibly ourself).
  176. //
  177. //                The part calls its FocusLost method to handle the 
  178. //                "reliquishing" of the particular focus.
  179. //------------------------------------------------------------------------------
  180. #pragma segment TextEditorActivation
  181.  
  182. SOM_Scope    void
  183. SOMLINK        TextEditor__CommitRelinquishFocus
  184.             (
  185.                 SampleCode_TextEditor*        somSelf,
  186.                 Environment*                ev,
  187.                 ODTypeToken                    focus,
  188.                 ODFrame*                    ownerFrame,
  189.                 ODFrame*                    proposedFrame
  190.             )
  191. {
  192. //    SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  193.     SOMMethodDebug("TextEditor","CommitRelinquishFocus");
  194.  
  195.     SOM_TRY
  196.     
  197.         // We agreed to give up the requested focus, so now we must do so.
  198.         somSelf->FocusLost(ev, focus, ownerFrame);
  199.     
  200.     SOM_CATCH_ALL
  201.     SOM_ENDTRY
  202. }
  203.  
  204. //------------------------------------------------------------------------------
  205. // Method:        AbortRelinquishFocus
  206. // Origin:        ODPart
  207. //
  208. // Description:    This method is called when another part (or possibly
  209. //                ourself) requested a focus for one of its display
  210. //                frames, but we returned kODFalse from
  211. //                BeginRelinqishFocus for one, or all, of the requested
  212. //                focus. At this point, we are being told to resume
  213. //                ownership of the focus.
  214. //
  215. //                The part calls its FocusAcquired method to handle the 
  216. //                re-"acquisition" of the particular focus.
  217. //------------------------------------------------------------------------------
  218. #pragma segment TextEditorActivation
  219.  
  220. SOM_Scope    void
  221. SOMLINK        TextEditor__AbortRelinquishFocus
  222.             (
  223.                 SampleCode_TextEditor*        somSelf,
  224.                 Environment*                ev,
  225.                 ODTypeToken                    focus,
  226.                 ODFrame*                    ownerFrame,
  227.                 ODFrame*                    proposedFrame
  228.             )
  229. {
  230.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  231.     SOMMethodDebug("TextEditor","AbortRelinquishFocus");
  232.  
  233.     // Some parts may have suspended some events in the BeginRelinquishFocus
  234.     // method. If so, they would resume those events here.
  235. }
  236.  
  237. //------------------------------------------------------------------------------
  238. // Method:        RelinquishAllFoci
  239. // Origin:        TextEditor
  240. //------------------------------------------------------------------------------
  241. #pragma segment TextEditorActivation
  242.  
  243. SOM_Scope    void
  244. SOMLINK        TextEditor__RelinquishAllFoci
  245.             (
  246.                 SampleCode_TextEditor*        somSelf,
  247.                 Environment*                ev,
  248.                 ODFrame*                    frame
  249.             )
  250. {
  251.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  252.     SOMMethodDebug("TextEditor","RelinquishAllFoci");
  253.  
  254.     SOM_TRY
  255.  
  256.         ODArbitrator* arbitrator = ODGetSession(ev, somSelf)->GetArbitrator(ev);
  257.         
  258.         TRY
  259.  
  260.             TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fSelectionFocus);
  261.             if ( ODObjectsAreEqual(ev, focusFrame, frame) )
  262.             {
  263.                 arbitrator->RelinquishFocus(ev, gGlobals->fSelectionFocus, frame);
  264.                 somSelf->FocusLost(ev, gGlobals->fSelectionFocus, frame);
  265.             }
  266.  
  267.         CATCH_ALL
  268.         ENDTRY
  269.  
  270.         TRY
  271.  
  272.             TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fMenuFocus);
  273.             if ( ODObjectsAreEqual(ev, focusFrame, frame) )
  274.             {
  275.                 arbitrator->RelinquishFocus(ev, gGlobals->fMenuFocus, frame);
  276.                 somSelf->FocusLost(ev, gGlobals->fMenuFocus, frame);
  277.             }
  278.  
  279.         CATCH_ALL
  280.         ENDTRY
  281.  
  282.         TRY
  283.  
  284.             TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fClipboardFocus);
  285.             if ( ODObjectsAreEqual(ev, focusFrame, frame) )
  286.             {
  287.                 arbitrator->RelinquishFocus(ev, gGlobals->fClipboardFocus, frame);
  288.                 somSelf->FocusLost(ev, gGlobals->fMenuFocus, frame);
  289.             }
  290.  
  291.         CATCH_ALL
  292.         ENDTRY
  293.  
  294.         TRY
  295.  
  296.             TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fKeyFocus);
  297.             if ( ODObjectsAreEqual(ev, focusFrame, frame) )
  298.             {
  299.                 arbitrator->RelinquishFocus(ev, gGlobals->fKeyFocus, frame);
  300.                 somSelf->FocusLost(ev, gGlobals->fKeyFocus, frame);
  301.             }
  302.  
  303.         CATCH_ALL
  304.         ENDTRY
  305.  
  306.     SOM_CATCH_ALL
  307.     SOM_ENDTRY
  308. }
  309.  
  310. //------------------------------------------------------------------------------
  311. // Method:        PartActivated
  312. // Origin:        TextEditor
  313. //
  314. // Description:    This method is called when the part gets activated (by
  315. //                asking for the contents of its focus set or having focus
  316. //                transferred to it).
  317. //------------------------------------------------------------------------------
  318. #pragma segment TextEditorActivation
  319.  
  320. SOM_Scope    void
  321. SOMLINK        TextEditor__PartActivated
  322.             (
  323.                 SampleCode_TextEditor*        somSelf,
  324.                 Environment*                ev,
  325.                 ODFrame*                    frame
  326.             )
  327. {
  328.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  329.     SOMMethodDebug("TextEditor","PartActivated");
  330.  
  331.     SOM_TRY
  332.     
  333.         // We are required to re-validate the menubar before displaying it because
  334.         // any part can/could swap the base menubar at any time.
  335.         if ( !gGlobals->fMenuBar->IsValid(ev) )
  336.             somSelf->LoadMenus(ev);
  337.             
  338.         // Display our menu bar.
  339.         gGlobals->fMenuBar->Display(ev);
  340.  
  341.         // And set our "active" state.
  342.         CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
  343.         frameInfo->SetFrameActive(kODTrue);
  344.  
  345.         // ScriptRunner support.
  346.         if ( _fScriptPaletteExt && _fIsScriptRunnerOn )
  347.         {
  348.             _fScriptPaletteExt->Show(ev);
  349.             _fScriptPaletteExt->SetClient(ev, _fSelf);
  350.             _fIsScriptRunnerHidden = kODFalse;
  351.         }
  352.  
  353.         // Set up Textension to get idle time.
  354.         ODIdleFrequency ticks = _fTextension->GetIdleTime();
  355.         
  356.         ODGetSession(ev, somSelf)->GetDispatcher(ev)
  357.             ->RegisterIdle(ev, _fSelf, frame, ++ticks);
  358.         
  359.         // While we are active, we don't need to use the bottom line input window.
  360.         const TSMDocumentID    kAnyDoc = kODNULL;
  361.         UseInputWindow(kAnyDoc, kODFalse);
  362.         
  363.         // somSelf->ShowRulers()
  364.  
  365.     SOM_CATCH_ALL
  366.     SOM_ENDTRY
  367. }
  368.  
  369. //------------------------------------------------------------------------------
  370. // Method:        FocusAcquired
  371. // Origin:        ODPart
  372. //
  373. // Description:    This method is called when the Arbitrator has
  374. //                registered us as the "owner" of the particular focus.
  375. //                This can occur if a focus is requested, or if a focus
  376. //                is transfered to one of the part's display frames.
  377. //
  378. //                The part will display the menu bar when the menu focus
  379. //                is acquired, and mark a frame active if the selection
  380. //                focus is acquired.
  381. //------------------------------------------------------------------------------
  382. #pragma segment TextEditorActivation
  383.  
  384. SOM_Scope    void
  385. SOMLINK        TextEditor__FocusAcquired
  386.             (
  387.                 SampleCode_TextEditor*        somSelf,
  388.                 Environment*                ev,
  389.                 ODTypeToken                    focus,
  390.                 ODFrame*                    ownerFrame
  391.             )
  392. {
  393.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  394.     SOMMethodDebug("TextEditor","FocusAcquired");
  395.  
  396.     SOM_TRY
  397.     
  398.         if ( gGlobals->fUIFocusSet->Contains(ev, focus) )
  399.         {
  400.             if ( ODGetSession(ev, somSelf)->GetArbitrator(ev)
  401.                         ->RequestFocusSet(ev, gGlobals->fUIFocusSet, ownerFrame) )
  402.                 somSelf->PartActivated(ev, ownerFrame);
  403.         }
  404.  
  405.     SOM_CATCH_ALL
  406.     SOM_ENDTRY
  407. }
  408.  
  409. //------------------------------------------------------------------------------
  410. // Method:        FocusLost
  411. // Origin:        ODPart
  412. //
  413. // Description:    This method is called when the Arbitrator has
  414. //                unregistered us as the "owner" of the particular
  415. //                focus.
  416. //
  417. //                The part unmarks the active frame if the selection
  418. //                focus is lost.
  419. //------------------------------------------------------------------------------
  420. #pragma segment TextEditorActivation
  421.  
  422. SOM_Scope    void
  423. SOMLINK        TextEditor__FocusLost
  424.             (
  425.                 SampleCode_TextEditor*        somSelf,
  426.                 Environment*                ev,
  427.                 ODTypeToken                    focus,
  428.                 ODFrame*                    ownerFrame
  429.             )
  430. {
  431.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  432.     SOMMethodDebug("TextEditor","FocusLost");
  433.  
  434.     SOM_TRY
  435.     
  436.         CFrameInfo* frameInfo = (CFrameInfo*) ownerFrame->GetPartInfo(ev);
  437.     
  438.         if ( focus == gGlobals->fSelectionFocus )
  439.         {
  440.             // Set our frame state flag.
  441.             CFrameInfo* frameInfo = (CFrameInfo*) ownerFrame->GetPartInfo(ev);
  442.             frameInfo->SetFrameActive(kODFalse);
  443.             
  444.             // Handle ScriptRunner.
  445.             somSelf->UpdateScriptRunnerState(ev);
  446.             
  447.             if ( _fScriptPaletteExt && _fIsScriptRunnerOn )
  448.             {
  449.                 // If script runner is "on", but has been hidden already for
  450.                 // some reason, we don't need to do anything.
  451.                 if ( !_fIsScriptRunnerHidden )
  452.                 {
  453.                     _fScriptPaletteExt->Hide(ev);
  454.                     _fIsScriptRunnerHidden = kODTrue;
  455.                 }
  456.             }
  457.             
  458.             // Give up all foci.
  459.             somSelf->RelinquishAllFoci(ev, ownerFrame);
  460.                 // •• Warning: this causes this section of code to be called once
  461.                 //    recursively.  This should be fixed in the future.
  462.         }
  463.         else if ( focus == gGlobals->fMenuFocus )
  464.         {            
  465.             // Change the "Preferences" item back to the default.
  466.             // NOTE: OpenDoc should do this for us, but there is a bug that
  467.             // prevents it from doing so.
  468.             SetMenuCommandIndString(ev, kODCommandPreferences, kRuntimeStringsID, 
  469.                                     kOriginalPreferencesStrIndex);
  470.         }
  471.         else if ( focus == gGlobals->fKeyFocus )
  472.         {
  473.             ODGetSession(ev, somSelf)->GetDispatcher(ev)
  474.                                 ->UnregisterIdle(ev, _fSelf, ownerFrame);
  475.     
  476.             somSelf->ActivateTextension(ev, ownerFrame, kODFalse);
  477.             
  478.             // somSelf->HideRuler()
  479.         }
  480.  
  481.     SOM_CATCH_ALL
  482.     SOM_ENDTRY
  483. }
  484. //------------------------------------------------------------------------------
  485. // Method:        FocusLost
  486. // Origin:        ODPart
  487. //
  488. // Description:    This method is called when we need to check to see if we have 
  489. //                the correct setting for our internal field tracking the visibility
  490. //                of the ScriptRunner palette because the palette could have been 
  491. //                hidden by the user clicking in the close box, in which case we 
  492. //                don't get informed.
  493. //------------------------------------------------------------------------------
  494. #pragma segment TextEditorActivation
  495.  
  496. SOM_Scope    void
  497. SOMLINK        TextEditor__UpdateScriptRunnerState
  498.             (
  499.                 SampleCode_TextEditor*        somSelf,
  500.                 Environment*                ev
  501.             )
  502. {
  503.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  504.     SOMMethodDebug("TextEditor","FocusLost");
  505.  
  506.     SOM_TRY
  507.     
  508.         if ( _fScriptPaletteExt && _fIsScriptRunnerOn )
  509.         {
  510.             // If script runner is "on", but has been hidden already for
  511.             // some reason, we don't need to do anything.
  512.             
  513.             if ( !_fIsScriptRunnerHidden )
  514.             {
  515.                 // We need to check to see if we have the correct setting for
  516.                 // our internal field because the palette could have been hidden
  517.                 // by the user clicking in the close box, in which case we don't
  518.                 // get informed.
  519.                 if ( !_fScriptPaletteExt->IsPaletteVisible(ev) )
  520.                 {
  521.                     _fScriptPaletteExt->Hide(ev);
  522.                     ODReleaseObject(ev, _fScriptPaletteExt);
  523.  
  524.                     _fIsScriptRunnerHidden = kODFalse;
  525.                     _fIsScriptRunnerOn = kODFalse;
  526.                     
  527.                     if ( !_fReadOnlyStorage )
  528.                         somSelf->SetDirty(ev);
  529.                 }
  530.             }
  531.         }
  532.  
  533.     SOM_CATCH_ALL
  534.     SOM_ENDTRY
  535. }
  536.  
  537. //------------------------------------------------------------------------------
  538. // Method:        Activate
  539. // Origin:        TextEditor
  540. //
  541. // Description:    This method is called by the part when a kODEvtMouseUp
  542. //------------------------------------------------------------------------------
  543. #pragma segment TextEditorActivation
  544.  
  545. SOM_Scope    ODBoolean
  546. SOMLINK        TextEditor__Activate
  547.              (
  548.                 SampleCode_TextEditor*        somSelf,
  549.                 Environment*                ev,
  550.                 ODFacet*                    facet
  551.             )
  552. {
  553.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  554.     SOMMethodDebug("TextEditor","Activate");
  555.  
  556.     ODBoolean result = kODTrue;
  557.  
  558.     SOM_TRY
  559.     
  560.         ODWindow* window = facet->GetWindow(ev);
  561.  
  562.         // Activate inactive windows on the first mouse up event.
  563.         if ( !window->IsActive(ev) )
  564.             window->Select(ev);
  565.         // Activate the frame (if needed) on all subsequent mouse up events.
  566.         else
  567.         {
  568.             // Activate the frame (if needed).
  569.             
  570.             ODFrame*    frame = facet->GetFrame(ev);
  571.             CFrameInfo* frameInfo = (CFrameInfo*)frame->GetPartInfo(ev);
  572.             
  573.             ODBoolean active = kODTrue;
  574.             
  575.             // If this frame is not the active one, activate it by requesting
  576.             // the appropriate foci.
  577.     
  578.             if ( frameInfo->IsFrameActive() == kODFalse )
  579.             {
  580.                 if ( somSelf->ActivateFrame(ev, frame) )
  581.                 {
  582.                     // Keep track of which facet was the last active for
  583.                     // various maintenance/drawing reasons.
  584.                     frameInfo->SetActiveFacet(facet);
  585.     
  586.                     // If the frame successfully becomes active, then
  587.                     // we activate Textension. Note that this call must
  588.                     // occur after the "active" facet has been set.
  589.                     somSelf->ActivateTextension(ev, frame, kODTrue);
  590.                 }
  591.                 else
  592.                 {
  593.                     // We were unsuccessful in activating our frame.
  594.                     result = kODFalse;
  595.                 }
  596.             }
  597.         }
  598.         
  599.     SOM_CATCH_ALL
  600.     SOM_ENDTRY
  601.     
  602.     return result;
  603. }
  604.  
  605. //------------------------------------------------------------------------------
  606. // Method:        ActivateFrame
  607. // Origin:        TextEditor
  608. //
  609. // Description:    This method is called by the part when a kODEvtMouseUp
  610. //                occurs in an inactive frame in an active window, and
  611. //                when an OpenDoc document comes forward.
  612. //
  613. //                The part activates the frame by requesting the
  614. //                UIFocusSet (created in Initialize) and by calling
  615. //                FocusAcquired if we were successful. The method
  616. //                returns true if no problems were encountered as a
  617. //                signal to the caller that the frame is now "active".
  618. //------------------------------------------------------------------------------
  619. #pragma segment TextEditorActivation
  620.  
  621. SOM_Scope    ODBoolean
  622. SOMLINK        TextEditor__ActivateFrame
  623.              (
  624.                 SampleCode_TextEditor*        somSelf,
  625.                 Environment*                ev,
  626.                 ODFrame*                    frame
  627.             )
  628. {
  629.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  630.     SOMMethodDebug("TextEditor","ActivateFrame");
  631.  
  632.     ODBoolean activated = kODFalse;
  633.  
  634.     SOM_TRY
  635.     
  636.         // Request the set of foci necessary to become active.
  637.         if ( ODGetSession(ev, somSelf)->GetArbitrator(ev)
  638.                     ->RequestFocusSet(ev, gGlobals->fUIFocusSet, frame) )
  639.         {
  640.             // Activate the part.
  641.             somSelf->PartActivated(ev, frame);
  642.             // We were able to become active.
  643.             activated = kODTrue;
  644.         }
  645.             
  646.     SOM_CATCH_ALL
  647.         activated = kODFalse;
  648.     SOM_ENDTRY
  649.  
  650.     // We sucessfully acquired the foci we need to be active.
  651.     return activated;
  652. }
  653.  
  654. //------------------------------------------------------------------------------
  655. // Method:        ActivateTextension
  656. // Origin:        TextEditor
  657. //
  658. // Description:    This method is called by the part when the text selection needs
  659. //                to be activated or deactivated.
  660. //------------------------------------------------------------------------------
  661. #pragma segment TextEditorActivation
  662.  
  663. SOM_Scope    void
  664. SOMLINK        TextEditor__ActivateTextension
  665.             (
  666.                 SampleCode_TextEditor*        somSelf,     
  667.                 Environment*                ev,
  668.                 ODFrame*                    frame,
  669.                 ODBoolean                    activate
  670.             )
  671. {
  672.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  673.     SOMMethodDebug("TextEditor","ActivateTextension");
  674.  
  675.     SOM_TRY
  676.  
  677.         CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
  678.         ODFacet*    facet = frameInfo->GetActiveFacet();
  679.         
  680.         if ( facet )
  681.         {
  682.             CFocus initiateDrawing(ev, facet);
  683.             _fTextension->Activate(activate);
  684.         }
  685.  
  686.     SOM_CATCH_ALL
  687.     SOM_ENDTRY
  688. }
  689.  
  690. //------------------------------------------------------------------------------
  691. // Method:        ActivateScrollbars
  692. // Origin:        TextEditor
  693. //
  694. // Description:    This method is called by the part when
  695. //------------------------------------------------------------------------------
  696. #pragma segment TextEditorActivation
  697.  
  698. SOM_Scope    void
  699. SOMLINK        TextEditor__ActivateScrollbars
  700.             (
  701.                 SampleCode_TextEditor*        somSelf,     
  702.                 Environment*                ev,
  703.                 ODBoolean                    activate
  704.             )
  705. {
  706.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  707.     SOMMethodDebug("TextEditor","ActivateScrollbars");
  708.  
  709.     SOM_TRY
  710.  
  711.         if ( _fVScrollbar )
  712.             HiliteControl(_fVScrollbar, activate ? 0 : 255);
  713.         if ( _fHScrollbar )
  714.             HiliteControl(_fHScrollbar, activate ? 0 : 255);
  715.  
  716.     SOM_CATCH_ALL
  717.     SOM_ENDTRY
  718. }
  719.  
  720. //------------------------------------------------------------------------------
  721. // Method:        WindowActivating
  722. // Origin:        TextEditor
  723. //
  724. // Description:    This method is called by the part when a window activation
  725. //                event (kODEvtActivate) occurs.
  726. //
  727. //                The part remembers the frame's active state and restores it when
  728. //                events come in. If the frame is active and the window is being
  729. //                sent into the background, remember to reactivate the part when
  730. //                the window is reactivated.
  731. //------------------------------------------------------------------------------
  732. #pragma segment TextEditorActivation
  733.  
  734. SOM_Scope    void
  735. SOMLINK        TextEditor__WindowActivating
  736.              (
  737.                 SampleCode_TextEditor*        somSelf,
  738.                 Environment*                ev,
  739.                 ODFrame*                    frame,
  740.                 ODBoolean                    activating
  741.             )
  742. {
  743.     SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
  744.     SOMMethodDebug("TextEditor","WindowActivating");
  745.  
  746.     // The ruler frame should never have an "active" facet, nor any foci, so
  747.     // we don't want to set any "activation" flags.
  748.     if ( frame->GetPresentation(ev) == gGlobals->fRulerPresentation )
  749.         return;
  750.  
  751.     SOM_TRY
  752.  
  753.         CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
  754.         
  755.         if ( activating && frameInfo->FrameNeedsReactivating() )
  756.         {
  757.             // The window is being activated, so acquire our foci.
  758.             if ( somSelf->ActivateFrame(ev, frame) )
  759.             {
  760.                 frameInfo->SetFrameReactivate(kODFalse);
  761.         
  762.                 // If the frame successfully becomes active, then
  763.                 // we activate Textension. Note that this call must
  764.                 // occur after the "active" facet has been set.
  765.                 somSelf->ActivateTextension(ev, frame, kODTrue);
  766.             }
  767.         }
  768.         else if ( !activating && frameInfo->IsFrameActive() )
  769.         {
  770.             // The window is being deactivated and we have the active part.
  771.             // So give up our foci and remind ourselves that we need to request
  772.             // the focus when the window is reactivated.
  773.             
  774.             frameInfo->SetFrameReactivate(kODTrue);
  775.             
  776.             // Give up all foci.
  777.             somSelf->RelinquishAllFoci(ev, frame);
  778.         }
  779.     
  780.         // De/activate the scrollbars.
  781.         somSelf->ActivateScrollbars(ev, activating);
  782.  
  783.     SOM_CATCH_ALL
  784.     SOM_ENDTRY
  785. }
  786.  
  787.